package com.smartlifev30.baiwei.view.recyclerViewComponent.sticky;

import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;



/**
 * @author tys
 * @date 2017/10/14
 */
public class StickyItemDivider extends RecyclerView.ItemDecoration {

    private int mLineHeight = 1;



    /**
     * 计算 item间间隙(偏移)(是普通分割线 ,还是title)
     */
    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewLayoutPosition();
        Rect rect = new Rect();
        if ((position + 1) % 3 == 0) {
            rect.right = 0;
        } else {
            rect.right = mLineHeight;
        }
        rect.bottom = mLineHeight;
        outRect.set(rect);
    }


//    /**
//     * 上层绘制,绘制顶部悬停title
//     */
//    @Override
//    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
//        super.onDrawOver(c, parent, state);
//        int left = parent.getPaddingLeft();
//        int right = parent.getMeasuredWidth() - parent.getPaddingRight();
//        int top = parent.getPaddingTop();
//        int bottom = top + mTitleHeight;
//        mPaint.setColor(titleBackgroundColor);
//        c.drawRect(left, top, right, bottom, mPaint);
//        int pos = ((LinearLayoutManager) (parent.getLayoutManager())).findFirstVisibleItemPosition();
//        if (pos != RecyclerView.NO_POSITION) {
//            drawText(c, adapter.getData(pos).stickTitle(), left + mTitleHeight * 0.25f, bottom - mTitleHeight * 0.25f);
//        }
//    }


}
